package com.dq.repository.record;

import com.dq.domain.orders.UserOrder;
import com.dq.domain.record.ProfitRecord;
import com.dq.domain.sys.user.user.base.SysUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;

/**
 * @Author luchangtong
 * @Date 2019/11/25 9:59
 */
@Repository
public interface ProfitRecordRepository extends JpaRepository<ProfitRecord, Long> {
    @Query("select COALESCE(sum(changeNum),0) from ProfitRecord where profitChangeType = ?1 and changeProfitType= ?2 and user= ?3")
    BigDecimal sumProfitRecordAdd(ProfitRecord.ProfitChangeType profitChangeType,ProfitRecord.ChangeProfitType changeProfitType,SysUser user);
    @Query("select sum(changeNum) from ProfitRecord where profitChangeType = ?1")
    BigDecimal sumProfitRecordLess(ProfitRecord.ProfitChangeType profitChangeType);
    ProfitRecord findByUserOrderAndUser(UserOrder userOrder ,SysUser sysUser);
}
